package com.halflife;

import com.halflife.comeElectricity.user.User;
import com.halflife.framework.generator.GenerateDDL;
import com.halflife.framework.generator.GenerateDomain;
import com.halflife.parameter.template.CompanyJson;
import com.halflife.parameter.template.ReturnJson;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * Created by zhaoyf on 2018/2/25.
 */
public class Generator {
    private void importCompany(long offset)throws Exception{
        RestTemplate restTemplate = new RestTemplate();
        ReturnJson returnJson = restTemplate.getForObject(new URI("https://api.hubapi.com/companies/v2/companies/paged?hapikey=20eca147-5b6e-4ad4-8bfa-1f54fa43742e&properties=name&limit=250&offset="+offset), ReturnJson.class);
        System.out.println(returnJson.getCompanies().size());
        if (returnJson.getHasMore()) {
            importCompany(returnJson.getOffset());
        }

    }
    @Test
    public void test(){
        try {
            Generator generator = new Generator();
            generator.importCompany(0);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
    }
    @Test
    public void charTest() {
        byte[] b_text="?".getBytes();
        for (int i = 0; i < b_text.length; i++)
        {
            if((b_text[i] & 0xF8)== 0xF0){
                for (int j = 0; j < 4; j++) {
                    b_text[i+j]=0x30;
                }
                i+=3;
            }
        }
        String title=new String(b_text);
        System.out.println(title);
    }
    @Test
    public void test1() {
        GenerateDDL ddl = new GenerateDDL(User.class);
        ddl.createTable();
    }
    @Test
    public void test2() {
        try {
            GenerateDomain domain = new GenerateDomain();
            domain.generateDomainAndRepository(User.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test3(){
        System.out.println(Integer.MAX_VALUE);
    }
}
